package pattern.observer.jdk;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by boot on 8/31/15.
 */
public class WeatherObserver implements Observer {
    private String observerName;

    public String getObserverName() {
        return observerName;
    }

    public void setObserverName(String observerName) {
        this.observerName = observerName;
    }

    public void update(Observable o, Object arg) {
        // push
        System.out.format("%s收到了消息，目标推送过来的是:%s%n", observerName, arg);

        // pull
        WeatherSubject ws = (WeatherSubject) o;
        System.out.format("%s收到了消息，主动到目标中去拉，拉取的内容是：%s%n", observerName, ws.getContent());

    }
}
